package com.orangelife.webservice.service.property.impl;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Response;

import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.omg.CosNaming.IstringHelper;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.orangelife.exception.AppBizException;
import com.orangelife.redis.core.redis.session.redisSession.WebServiceSession;
import com.orangelife.service.bill.impl.BillService;
import com.orangelife.service.propFeeComm.IPropFeeCommService;
import com.orangelife.service.propFeeComm.model.PropFeeCommDto;
import com.orangelife.service.propFeeCommInfo.IPropFeeCommInfoService;
import com.orangelife.service.property.PropCollectionService;
import com.orangelife.service.property.model.UserBean;
import com.orangelife.setting.constant.CodeConst;
import com.orangelife.setting.constant.InfoConst;
import com.orangelife.utils.PropertyUtils;
import com.orangelife.utils.StringUtils;
import com.orangelife.webservice.base.BaseService;
import com.orangelife.webservice.service.property.PropCollectionWebService;
import com.orangelife.webservice.service.property.entity.PropComputeBean;
import com.orangelife.webservice.service.property.entity.PropNoticeBean;

@Service("propCollectionWebService")
public class PropCollectionWebServiceImpl extends BaseService implements
		PropCollectionWebService {

	@Resource(name = "propCollectionService")
	private PropCollectionService propCollectionService;
	@Resource(name = "propFeeCommInfoService")
	private IPropFeeCommInfoService propFeeCommInfoService;
	@Resource(name = "propFeeCommService")
	private IPropFeeCommService propFeeCommService;
	PropNoticeBean propNoticeBeannew = null;
	UserBean userbeannew = null;
	String planidnew = "";

	@Override
	public Response feeDetail(HttpServletRequest servletRequest, String isPre,
			String commID, String apartmentID, String FeeTypeID,
			String ts_start, String ts_end, String orderbytype)
			throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}

		if (StringUtils.isBlank(commID)) {
			return this.abnormalResp(99, "小区号不能为空！");
		}
		if (StringUtils.isBlank(apartmentID)) {
			return this.abnormalResp(99, "房间号不能为空！");

		}
//		//判断别名
//		if (!StringUtils.isBlank(otherName) && otherName!="undefined" && otherName!="" && otherName!=null) {
//			otherName=java.net.URLDecoder.decode(otherName,"utf-8");
//
//		}

		// 获取固定费用已生成日期

		List<Map<String, Object>> lisitems = propCollectionService.feeDetail(
				isPre, commID, apartmentID, FeeTypeID, ts_start, ts_end,
				orderbytype);
		return this.normalResp(1, 10, 0l, PropertyUtils.turnToEntity(lisitems));
	}

	@Override
	public Response FeeType(HttpServletRequest servletRequest, String commID,
			String apartmentID) throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}

		if (StringUtils.isBlank(commID)) {
			return this.abnormalResp(99, "小区号不能为空！");
		}
		if (StringUtils.isBlank(apartmentID)) {
			return this.abnormalResp(99, "房间号不能为空！");

		}

		List<Map<String, Object>> lisitems = propCollectionService.FeeType(
				commID, apartmentID);
		return this.normalResp(1, 10, 0l, lisitems);
	}

	@Override
	public Response feecompute(HttpServletRequest servletRequest,
			PropComputeBean propComputeBean) throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}
		if (propComputeBean.getFeeTypeIDs().length <= 0) {
			return this.abnormalResp(99, "请够选预缴类目！");
		}
		List<Map<String, Object>> lisitems = propCollectionService
				.feecompute(propComputeBean);
		return this.normalResp(1, 10, 0l, lisitems);
	}

	@Override
	public Response PayBill(HttpServletRequest servletRequest,
			PropComputeBean propComputeBean) throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}
		Map<String, Object> map = propCollectionService.PayBill(
				propComputeBean, userbean);
		// System.out.println("gggggggggggggggggggg:"+map.toString());
		// //插入缴费账单明细表------------------------------
		// propCollectionService.insertpropfeepaydetail(map);
		return this.normalResp();
	}

	@Override
	public Response getpaybill(HttpServletRequest servletRequest,
			String commID, String apartmentID, String apartmentNum,
			String invoice, String invoiceNum, String isInvoice,
			String invoiceStime, String invoiceEtime, String payStime,
			String payEtime, String payTypes, String ownerName,
			String pageIndex, String pageSize) throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		if (!StringUtils.isBlank(payTypes)) {

			map.put("payTypes", payTypes.split(","));

		}
		map.put("ownerName", ownerName);

		map.put("commID", commID);
		map.put("apartmentID", apartmentID);
		map.put("invoice", invoice);
		map.put("invoiceStime", invoiceStime);
		map.put("invoiceEtime", invoiceEtime);
		map.put("payStime", payStime);
		map.put("payEtime", payEtime);

		map.put("apartmentNum", apartmentNum);
		map.put("invoiceNum", invoiceNum);
		map.put("isInvoice", isInvoice);
		map.put("pageIndex", pageIndex);
		map.put("pageSize", pageSize);
		List<Map<String, Object>> lisitems = propCollectionService
				.getpaybill(map);
		Long total = ((Page<Map<String, Object>>) lisitems).getTotal();

		return this.normalResp(Integer.valueOf(pageIndex),
				Integer.valueOf(pageSize), total, lisitems);
	}

	@Override
	public Response getpaybillitem(HttpServletRequest servletRequest,
			String paybillID) throws Exception {

		List<Map<String, Object>> lisitems = propCollectionService
				.getpaybillitem(paybillID);
		if (lisitems.size() > 0) {
			return this.normalResp(lisitems.get(0));
		} else {
			return this.normalResp(lisitems);
		}

	}

	@Override
	public Response updatepaybill(HttpServletRequest servletRequest,
			PropComputeBean propComputeBean) throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}

		if (com.orangelife.utils.StringUtils.length(propComputeBean
				.getInvoiceNum()) > 60) {

			return this.abnormalResp(10006, "发票长度过长");

		}

		propCollectionService.updatepaybill(propComputeBean, userbean);

		return this.normalResp();
	}

	@Override
	public Response deletepaybill(HttpServletRequest servletRequest,
			String paybillID) throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}
		propCollectionService.deletepaybill(paybillID, userbean);
		return this.normalResp();
	}

	public UserBean getUserBean(HttpServletRequest servletRequest) {
		UserBean user = new UserBean();
		WebServiceSession webServiceSession = this
				.getWebServiceSession(servletRequest);
		if (webServiceSession == null) {
			// user.setUserID("1111");
			// user.setUserName("hhhhhhh");
			return null;

		} else {
			user.setUserID(webServiceSession.getUserID());
			user.setUserName(webServiceSession.getRealname());
		}
		return user;

	}

	@Override
	public Response procprintplan(HttpServletRequest servletRequest,
			PropNoticeBean propNoticeBean) throws Exception {

		WebServiceSession webServiceSession=this.getWebServiceSession(servletRequest);

		if (StringUtils.isBlank(propNoticeBean.getCommID())) {
			return this.abnormalResp(99, "小区号不能为空！");
		}
		if (StringUtils.isBlank(propNoticeBean.getCommName())) {
			return this.abnormalResp(99, "小区名称不能为空不能为空！");
		}
		if (StringUtils.isBlank(propNoticeBean.getBuildingID())) {
			return this.abnormalResp(99, "楼栋号不能为空！");
		}
		if (StringUtils.isBlank(propNoticeBean.getStartTime())) {
			return this.abnormalResp(99, "开始时间不能为空！");
		}
		if (StringUtils.isBlank(propNoticeBean.getEndTime())) {
			return this.abnormalResp(99, "结束时间不能为空！");
		}
		final String pmID=webServiceSession.getPmID();
//		logger.info("获取PmID"+pmID);
		UserBean userbean = null;
		String planid = "";
		planid = propCollectionService.createplan(propNoticeBean, userbean);
		propNoticeBeannew = propNoticeBean;
		userbeannew = userbean;
		planidnew = planid;
		new Thread() {
			public void run() {
				try {
					planidnew = propCollectionService.procprintplanNew(
							propNoticeBeannew, userbeannew, planidnew,pmID);
				} catch (AppBizException e) {

					// 终止打印计划
					try {
						propCollectionService.cutplan(planidnew, "4");
					} catch (AppBizException e1) {

						e1.printStackTrace();
					} catch (ParseException e1) {

						e1.printStackTrace();
					}
					e.printStackTrace();
				} catch (ParseException e) {

					// 终止打印计划
					try {
						propCollectionService.cutplan(planidnew, "4");
					} catch (AppBizException e1) {

						e1.printStackTrace();
					} catch (ParseException e1) {

						e1.printStackTrace();
					}
					e.printStackTrace();
				} catch (Exception e) {

					// 终止打印计划
					try {
						propCollectionService.cutplan(planidnew, "4");
					} catch (AppBizException e1) {

						e1.printStackTrace();
					} catch (ParseException e1) {

						e1.printStackTrace();
					}
					e.printStackTrace();
				}
			}

		}.start();
		return this.normalResp();
	}

	@Override
	public Response getprintplan(HttpServletRequest servletRequest,
			String commID, String planType, String pageIndex, String pageSize)
			throws Exception {

		if (StringUtils.isBlank(commID)) {
			return this.abnormalResp(99, "小区号不能为空！");
		}
		if (StringUtils.isBlank(planType)) {
			return this.abnormalResp(99, "计划类型不能为空！");

		}
		List<Map<String, Object>> list = propCollectionService.getprintplan(
				commID, planType, pageIndex, pageSize);
		Long total = ((Page<Map<String, Object>>) list).getTotal();

		return this.normalResp(Integer.valueOf(pageIndex),
				Integer.valueOf(pageSize), total, list);
	}

	@Override
	public Response savedic(HttpServletRequest servletRequest,
			PropNoticeBean propNoticeBean) throws Exception {
		UserBean userbean = null;
		List<Map<String, Object>> list = propCollectionService.getdic(
				propNoticeBean.getCommID(), propNoticeBean.getCode());
		if (list.size() > 0) {
			propCollectionService.updatedic(propNoticeBean, userbean);
		} else {
			propCollectionService.savedic(propNoticeBean, userbean);
		}

		return this.normalResp();
	}

	@Override
	public Response getdic(HttpServletRequest servletRequest, String commID,
			String code) throws Exception {

		List<Map<String, Object>> list = propCollectionService.getdic(commID,
				code);
		//
		// if(list!=null&&list.size()>0)
		// return this.normalResp(list.get(0));
		// else{
		// return this.normalResp(null);
		//
		// }

		return this.normalResp(1, 10, 0l, list);
	}

	@Override
	public Response queryshareRecord(HttpServletRequest servletRequest,
			String commID, String type, String period, String search)
			throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("commID", commID);
		map.put("type", type);// 0 ：公摊 1：住户
		map.put("period", period);// 0 ：公摊 1：住户
		map.put("search", search);
		List<Map<String, Object>> list = propCollectionService
				.queryshareRecord(map);
		return this.normalResp(1, 10, 0l, list);
	}

	@Override
	public Response saveshareRecord(HttpServletRequest servletRequest,
			PropNoticeBean propNoticeBean) throws Exception {

		if (BillService.getFeeStatus(propNoticeBean.getCommID())) {

			return this.abnormalResp(99, "账单正在生成中！");

		}

		UserBean userbean = null;
		propCollectionService.saveshareRecord(propNoticeBean, userbean);
		return this.normalResp();
	}

	@Override
	public Response queryapartmentRecord(HttpServletRequest servletRequest,
			String commID, String type, String buildingID, String unitID,
			String meterTypeID, String isempty, String pageIndex,
			String pageSize) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("commID", commID);
		map.put("type", type);// 0 ：公摊 1：住户
		map.put("unitID", unitID);
		map.put("buildingID", buildingID);
		map.put("meterTypeID", meterTypeID);
		map.put("pageIndex", pageIndex);
		map.put("pageSize", pageSize);
		map.put("isempty", isempty);

		List<Map<String, Object>> list = propCollectionService
				.queryapartmentRecord(map, pageIndex, pageSize);
		Long total = ((Page<Map<String, Object>>) list).getTotal();

		return this.normalResp(Integer.valueOf(pageIndex),
				Integer.valueOf(pageSize), total, list);
	}

	public Response queryapartmentRecords(HttpServletRequest servletRequest,
			String period, String commID, String type, String buildingID,
			String unitID, String meterTypeID, String isempty,
			String pageIndex, String pageSize) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("commID", commID);
		map.put("period", period);
		map.put("type", type);// 0 ：公摊 1：住户
		map.put("unitID", unitID);
		map.put("buildingID", buildingID);
		map.put("meterTypeID", meterTypeID);
		map.put("pageIndex", pageIndex);
		map.put("pageSize", pageSize);
		map.put("isempty", isempty);

		List<Map<String, Object>> list = propCollectionService
				.queryapartmentRecords(map, pageIndex, pageSize);
		Long total = ((Page<Map<String, Object>>) list).getTotal();
		list = PropertyUtils.turnToEntity(list);
		return this.normalResp(Integer.valueOf(pageIndex),
				Integer.valueOf(pageSize), total, list);
	}


	/**
	 * 首次公摊表读数录入
	 * @param servletRequest
	 * @param propNoticeBean
	 * @return
	 * @throws Exception
	 */
	public Response saveOneshareRecord(HttpServletRequest servletRequest,
									   PropNoticeBean propNoticeBean) throws Exception {


		if (BillService.getFeeStatus(propNoticeBean.getCommID())) {
			return this.abnormalResp(99, "账单正在生成中！");
		}

		UserBean userbean = null;
		propCollectionService.saveOneshareRecord(propNoticeBean, userbean);
		return this.normalResp();
	}


	@Override
	public Response queryapartmentRecordss(HttpServletRequest servletRequest,
			Map<String, Object> map) throws Exception {

		String pageIndex = "1";
		String pageSize = "10";

		if (map.containsKey("pageIndex")) {
			pageIndex = map.get("pageIndex").toString();
		}
		if (map.containsKey("pageSize")) {
			pageSize = map.get("pageSize").toString();
		}
		List<Map<String, Object>> list = propCollectionService
				.queryapartmentRecords(map, pageIndex, pageSize);
		Long total = ((Page<Map<String, Object>>) list).getTotal();
		list = PropertyUtils.turnToEntity(list);
		return this.normalResp(Integer.valueOf(pageIndex),
				Integer.valueOf(pageSize), total, list);
	}

	@Override
	public Response queryapartmentRecordsum(HttpServletRequest servletRequest,
			String commID, String type, String buildingID, String unitID,
			String meterTypeID, String isempty) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("commID", commID);
		map.put("type", type);// 0 ：公摊 1：住户
		map.put("unitID", unitID);
		map.put("buildingID", buildingID);
		map.put("meterTypeID", meterTypeID);
		map.put("isempty", isempty);
		Map<String, Object> mapsum = propCollectionService
				.queryapartmentRecordsum(map);

		return this.normalResp(mapsum);
	}

	@Override
	public Response queryapartmentRecordsums(HttpServletRequest servletRequest,
			String period, String commID, String type, String buildingID,
			String unitID, String meterTypeID, String isempty) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("period", period);
		map.put("commID", commID);
		map.put("type", type);// 0 ：公摊 1：住户
		map.put("unitID", unitID);
		map.put("buildingID", buildingID);
		map.put("meterTypeID", meterTypeID);
		map.put("isempty", isempty);
		Map<String, Object> mapsum = propCollectionService
				.queryapartmentRecordsums(map);

		return this.normalResp(mapsum);
	}

	@Override
	public Response downmodle(HttpServletRequest servletRequest,
			HttpServletResponse servletResponse, String commID, String comm,
			String type, String unitID, String buildingID, String meterTypeID)
			throws Exception {
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
		final String filename = df.format(new Date());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("commID", commID);
		map.put("type", type);// 0 ：公摊 1：住户
		map.put("unitID", unitID);
		map.put("buildingID", buildingID);
		map.put("meterTypeID", meterTypeID);

		List<Map<String, Object>> list = propCollectionService.downmodle(map);

		final PropFeeCommDto propFeeComm = propFeeCommService
				.findPropFeeCommByID(commID);
		HSSFWorkbook wb = new HSSFWorkbook(); // --->创建了一个excel文件
		HSSFSheet sheet = wb.createSheet("住户水电模板"); // --->创建了一个工作簿
		HSSFDataFormat format = wb.createDataFormat(); // --->单元格内容格式
		sheet.setColumnWidth((short) 0, 20 * 300); // ---》设置单元格宽度，因为一个单元格宽度定了那么下面多有的单元格高度都确定了所以这个方法是sheet的
		sheet.setColumnWidth((short) 1, 20 * 300); // --->第一个参数是指哪个单元格，第二个参数是单元格的宽度
		sheet.setColumnWidth((short) 2, 20 * 300);
		sheet.setColumnWidth((short) 3, 20 * 300);
		sheet.setColumnWidth((short) 4, 20 * 300);
		// sheet.setColumnWidth((short)5, 20* 300);
		sheet.setDefaultRowHeight((short) 300); // ---->有得时候你想设置统一单元格的高度，就用这个方法
		sheet.protectSheet("123456");
		HSSFRow row0 = sheet.createRow(0);
		HSSFCell cell0_00 = row0.createCell(0);
		cell0_00.setCellValue(commID);
		HSSFCell cell0_01 = row0.createCell(1);
		cell0_01.setCellValue("");
		HSSFCell cell0_02 = row0.createCell(2);
		cell0_02.setCellValue("");
		HSSFCell cell0_03 = row0.createCell(3);
		cell0_03.setCellValue("");
		HSSFRow row1 = sheet.createRow(1);// --->创建一行
		HSSFCellStyle style0 = wb.createCellStyle(); // 样式对象
		style0.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直
		style0.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
		HSSFCellStyle style1 = wb.createCellStyle(); // 样式对象
		style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直
		style1.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
		style1.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.000"));
		style1.setLocked(false);
		HSSFCell cell0_0 = row1.createCell(0);
		cell0_0.setCellValue("ID");
		cell0_0.setCellStyle(style0);
		HSSFCell cell1_0 = row1.createCell(1);
		cell1_0.setCellValue("房号");
		cell1_0.setCellStyle(style0);
		// HSSFCell cell2_0 = row0.createCell(2);
		// cell2_0.setCellValue("类目id");
		// cell2_0.setCellStyle(style0);
		HSSFCell cell3_0 = row1.createCell(2);
		cell3_0.setCellValue("类目名称");
		cell3_0.setCellStyle(style0);
		HSSFCell cell4_0 = row1.createCell(3);
		cell4_0.setCellValue("表读数");
		cell4_0.setCellStyle(style0);
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> modlemap = list.get(i);
			HSSFRow row = sheet.createRow(i + 2);
			HSSFCell cell0 = row.createCell(0);
			cell0.setCellValue(modlemap.get("meter_id").toString());
			cell0.setCellStyle(style0);

			HSSFCell cell1 = row.createCell(1);
			cell1.setCellValue(modlemap.get("building_name").toString()
					+ "-"
					+ (StringUtils.isBlank(StringUtils.toString(
							modlemap.get("unit_name"), "")) ? "" : modlemap
							.get("unit_name").toString() + "-")
					+ modlemap.get("apartment_num").toString());
			cell1.setCellStyle(style0);

			HSSFCell cell3 = row.createCell(2);
			cell3.setCellValue(modlemap.get("meter_name").toString());
			cell3.setCellStyle(style0);

			// --->设置为单元格内容为货币格式

			HSSFCell cell4 = row.createCell(3);
			cell4.setCellValue("");

			cell4.setCellStyle(style1);
		}

		FileOutputStream fileOut = null;
		try {
			// fileOut = new FileOutputStream("d:\\workbookvvv.xls");
			// wb.write(fileOut);
			// fileOut.close();
			System.out.print("OK");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (fileOut != null) {
				try {
					fileOut.close();
				} catch (IOException e) {

					e.printStackTrace();
				}
			}
		}

		String excelName = propFeeComm.getComm() + "住户表录入模板" + filename;
		servletResponse.setContentType("application/vnd.ms-excel");
		servletResponse.setHeader(
				"Content-Disposition",
				"attachment; filename="
						+ new String((excelName + ".xls").getBytes("UTF-8"),
								"iso8859-1"));
		servletResponse.setHeader("Pragma", "No-cache");
		servletResponse.setHeader("Cache-Control", "No-cache");
		servletResponse.setDateHeader("Expires", 0); // 这个地方一定要进行编码的转换要不然中文字符会出现乱码.

		OutputStream ouputStream = servletResponse.getOutputStream();
		wb.write(ouputStream);
		ouputStream.flush();
		ouputStream.close();

		return null;
	}

	@Override
	public Response uploadFileList(List<Attachment> attachments,
			HttpServletRequest request) throws AppBizException,
			InvalidFormatException, ParseException, IOException {

		UserBean userbean = null;
		Map<String, Object> resmap = propCollectionService.uploadFileList(
				attachments, request, userbean);
		if (resmap.get("code").equals("99")) {
			return this.abnormalResp(99, resmap.get("note").toString());
		}
		return this.normalResp();
	}

	@Override
	public Response querymetertype(HttpServletRequest servletRequest,
			String commID) throws Exception {

		List<Map<String, Object>> list = propCollectionService
				.querymetertype(commID);
		return this.normalResp(1, 10, 0l, list);
	}

	@Override
	public Response getpaybilltj(HttpServletRequest servletRequest,
			String commID, String apartmentID, String apartmentNum,
			String invoice, String invoiceNum, String isInvoice,
			String invoiceStime, String invoiceEtime, String payStime,
			String payEtime, String payTypes, String ownerName,
			String pageIndex, String pageSize) throws Exception {

		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		if (!StringUtils.isBlank(payTypes)) {

			map.put("payTypes", payTypes.split(","));

		}

		map.put("commID", commID);
		map.put("apartmentID", apartmentID);
		map.put("invoice", invoice);
		map.put("invoiceStime", invoiceStime);
		map.put("invoiceEtime", invoiceEtime);
		map.put("payStime", payStime);
		map.put("payEtime", payEtime);

		map.put("ownerName", ownerName);
		map.put("apartmentNum", apartmentNum);
		map.put("invoiceNum", invoiceNum);
		map.put("isInvoice", isInvoice);
		map.put("pageIndex", pageIndex);
		map.put("pageSize", pageSize);
		Map<String, Object> lisitems = propCollectionService.getpaybilltj(map);

		return this.normalResp(lisitems);
	}

	@Override
	public Response PayBillNew(HttpServletRequest servletRequest,
			PropComputeBean propComputeBean) throws Exception {
		UserBean userbean = getUserBean(servletRequest);
		if (userbean == null) {
			return this.abnormalResp(CodeConst.SYS_CODE_2001,
					InfoConst.SYS_INFO_2001);
		}
		// UserBean userbean = new UserBean();
		// userbean.setUserID("1");
		// userbean.setUserName("2");
		Map<String, Object> map = propCollectionService.PayBillNew(
				propComputeBean, userbean);
		return this.normalResp(map);
	}

	@Override
	public Response confirmCollection(HttpServletRequest servletRequest,
			String paybillId) throws Exception {
		if (StringUtils.isBlank(paybillId)) {
			return this.abnormalResp(100002, "账单ID不能为空");

		}
		propCollectionService.confirmCollection(paybillId);
		return this.normalResp();
	}

	@Override
	public Response getCollectionInfoByUserId(
			HttpServletRequest servletRequest, String userId) throws Exception {
		if (StringUtils.isBlank(userId)) {
			return this.abnormalResp(100002, "用户ID不能为空");

		}

		List<Map<String, Object>> list = propCollectionService
				.getCollectionInfoByUserId(userId);
		return this.normalResp(list);
	}

	@Override
	public Response queryshareRecords(HttpServletRequest servletRequest,
			String commID, String type, String period, String search)
			throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("commID", commID);
		map.put("type", type);// 0 ：公摊 1：住户
		map.put("period", period);// 0 ：公摊 1：住户
		map.put("search", search);
		List<Map<String, Object>> list = propCollectionService
				.queryshareRecords(map);
		return this.normalResp(1, 10, 0l, PropertyUtils.turnToEntity(list));
	}

}
